var  app = getApp();
const log =require('../../log.js');
const util=require('../../util.js');
let keys = '4UTBZ-PUWLX-UGS4R-TIK3C-WFL73-N4FWH';
const tabService = require("../../libs/tabService");
const QQMapWX = require('../../libs/qqmap-wx-jssdk.js');
const qqmapsdk = new QQMapWX({
  key:keys
});
Page({

    /**
     * 页面的初始数据
     */
    data: {
      itemIndex:0,
      margin:[]
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        let that=this;   
        console.log('--------options----')
        console.log(options);
        console.log('--------options----')
        var parent_id=options.parent_id;
        var store_id=options.store_id;
        var sn=options.sn;
        var id=options.id;
        if(store_id!=undefined){
          console.log('store_id1=>'+store_id)
          this.setData({
            store_id:store_id
          });
          wx.setStorageSync('store_id',store_id);
      }else{
        
            store_id=wx.getStorageSync('store_id');
        
        console.log('store_id2=>'+store_id)
          
        
        

        
      }
        if(sn!=undefined){
            this.setData({
                sn:sn
            });
            wx.setStorageSync('sn',sn);
        }

         var userInfo=wx.getStorageSync('userInfo'); 

        console.log('userInfo=>'+userInfo);
        var date=util.formatTime(new Date());
        log.info("Time:"+date+",page:index,options:"+JSON.stringify(options));
        log.info("Time:"+date+",page:index,store_id:"+store_id);
        //userInfo="";
        //userInfo="";
        if(userInfo==""){
            wx.navigateTo({
              url: '../login/index?parent_id='+parent_id+'&store_id='+store_id,
            })
        }
        wx.showShareMenu({
            menus: ['shareAppMessage'],
            success(res) {
             console.log('success')
              console.log(res)
            },
            fail(e) {
              console.log(e)
            }
          })    
     wx.hideShareMenu({
         menus:['shareTimeline'],
         success(res) {
            console.log('success')
             console.log(res)
           },
     })
      this.getCate(id);
        that.setData({
            platform:app.globalData.platform,
            city:app.globalData.city,
             userInfo:userInfo,
            width:app.globalData.windowWidth,
            height:app.globalData.windowHeight,
            statusBarHeight:app.globalData.statusBarHeight,
            navHeight:app.globalData.navHeight,
            marginTop:app.globalData.navTitleTop,
            domain:app.globalData.domain,
            uploadUrl:app.globalData.uploadUrl,
            imgUrls:app.globalData.imgUrls
          })
    },
    goIndex(){
        wx.setStorageSync('store_id',0);
        wx.reLaunch({
          url: '../index/index',
        })
    },
    goBack(){
        //wx.navigateBack();
        var pages = getCurrentPages();
        var currPage = pages[pages.length - 1];   //当前页面
        var prevPage = pages[pages.length - 2];  //上一个页面
       // prevPage.onRefresh()//刷新方法
        wx.navigateBack({
            delta:1
        });
      },
    getCate:function (id) {
        let that=this;
        wx.request({
          url: app.globalData.domain+'store/getCate',
          data:{id:id},
          success:res=>{
              console.log(res.data);
              var data=res.data;
              var station=data.station;
              var phone=data.phone;        
           
           
            
            that.setData({
                shareTitle:data.shareTitle,
                shareLogo:data.shareLogo,
                shareIndex:data.shareIndex,
                backgroud:data.backgroud,  
              cate:data.cate,
              banner:data.banner
            
            })
            }
        })
    },
    call(e){
      var phone=e.currentTarget.dataset.phone;
      wx.makePhoneCall({
        phoneNumber: phone,
      })
    },
    goto:function(e){
      console.log(e);
      var url=e.currentTarget.dataset.url;
      var parent_id=wx.getStorageSync('parent_id');
      var index=e.currentTarget.dataset.index;
      if(url=="#"){

      }else if(url=='phone'){
          wx.makePhoneCall({
            phoneNumber: '400-800-2177',
          })
      }else if(url=='coupon'){
          var date=util.formatTime(new Date());
          var face_value=e.currentTarget.dataset.face_value;
          var pay_money=e.currentTarget.dataset.pay_money;
          var yxq=e.currentTarget.dataset.yxq;
          var month=e.currentTarget.dataset.month;
           log.info("Time:"+date+",page:index,function:goto:,index"+index);
          this.getCoupon(face_value,month,yxq,pay_money);
      }else{
          if(index=='index'){
              wx.reLaunch({
                  url: url,
                })
          }else{
              console.log(url);
              wx.navigateTo({
                  url: url,
                })
          }
     
      }
    // console.log(url);
  },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    }
})